// package com.example.demoflink;
//
// import cn.hutool.core.io.FileUtil;
// import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
//
// /**
//  * @version 1.0.0
//  * @className: TestCount
//  * @description:
//  * @author: zhangjunfa
//  * @date: 2023/1/31 19:02
//  */
// public class TestCount {
//     public static void main(String[] args) {
//         StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//
//         EnvironmentSettings environmentSettings = EnvironmentSettings.newInstance().useBlinkPlanner().inStreamingMode().build();
//         StreamTableEnvironment tabEnv = StreamTableEnvironment.create(env, environmentSettings);
//
// // 将源数据写入临时文件并获取绝对路径
//         String contents =
//                 "张三,http://taobao.com/xxx,2021-05-10 10:00:00\n" +
//                         "张三,http://taobao.com/xxx,2021-05-10 10:00:10\n" +
//                         "张三,http://taobao.com/xxx,2021-05-10 10:00:49\n" +
//                         "张三,http://taobao.com/xxx,2021-05-10 10:01:05\n" +
//                         "张三,http://taobao.com/xxx,2021-05-10 10:01:58\n" +
//                         "张三,http://taobao.com/xxx,2021-05-10 10:02:10\n";
//         String path = FileUtil.createTempFile(contents);
//
//         String ddl = "CREATE TABLE user_clicks (\n" +
//                 "  username varchar,\n" +
//                 "  click_url varchar,\n" +
//                 "  ts TIMESTAMP(3),\n" +
//                 "  WATERMARK FOR ts AS ts - INTERVAL '2' SECOND\n" +
//                 ") WITH (\n" +
//                 "  'connector.type' = 'filesystem',\n" +
//                 "  'connector.path' = '" + path + "',\n" +
//                 "  'format.type' = 'csv'\n" +
//                 ")";
//
//         tabEnv.sqlUpdate(ddl);
//
// //对表数据进行sql查询，并将结果作为新表进行查询
//         String query = "SELECT\n" +
//                 "  TUMBLE_START(ts, INTERVAL '1' MINUTE),\n" +
//                 "  TUMBLE_END(ts, INTERVAL '1' MINUTE),\n" +
//                 "  username,\n" +
//                 "  COUNT(click_url)\n" +
//                 "FROM user_clicks\n" +
//                 "GROUP BY TUMBLE(ts, INTERVAL '1' MINUTE), username";
//
//         Table result = tabEnv.sqlQuery(query);
//
//         tabEnv.toAppendStream(result, Row.class).print();
//
//         env.execute();
//     }
// }
